package com.iqiyi.pps.epg.api.server.proxy;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.iqiyi.pps.epg.api.aop.annotation.SkipAuthCheck;
import com.iqiyi.pps.epg.api.aop.annotation.SkipInterfaceLog;
import com.iqiyi.pps.epg.api.model.web.query.TFilter;
import com.iqiyi.pps.epg.api.model.web.query.TPage;
import com.iqiyi.pps.epg.api.model.web.query.TResponse;
import com.iqiyi.pps.epg.api.model.web.record.*;
import com.iqiyi.pps.epg.api.server.web.record.RecordWebService;
import com.iqiyi.pps.epg.api.utils.Constants;
import com.iqiyi.pps.epg.api.utils.ServiceUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by karkarrotxu on 2018/4/11.
 */
@Service
public class RecordProxy extends BaseProxy {
    private static Logger logger = LoggerFactory.getLogger(RecordProxy.class);

    @SkipInterfaceLog
    public String getPlanLibraryList(String paramsObj, Integer pageNo, Integer pageSize) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            if (pageNo == null) {
                pageNo = 1;
            }
            if (pageSize == null) {
                pageSize = 20;
            }
            Map<String, String> params = new HashMap<>();
            if (paramsObj != null) {
                JSONObject jsonObject = JSONObject.parseObject(paramsObj);
                for (Map.Entry<String, Object> temp : jsonObject.entrySet()) {
                    params.put(temp.getKey(), temp.getValue() + "");
                }
            }
            TFilter tFilter = new TFilter();
            tFilter.setFilters(params);
            TPage page = new TPage(-1, pageNo, pageSize, "create_time", "desc", true);
            TRecordPlanLibraryPage dataPage = service.findTRecordPlanLibraryPage(page, tFilter);
            if (dataPage != null) {
                return Constants.getResponse(Constants.CODE_SUC, dataPage, "操作成功").toJsonString();
            } else {
                return Constants.getJsonResponse(Constants.CODE_ERROR, null, PARAMETER_ERROR);
            }
        } catch (Exception e) {
            logger.error("[getPlanLibraryList]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    public String doPlanSave(String dataString) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            TRecordPlan recordPlan = JSONObject.parseObject(dataString, TRecordPlan.class);
            recordPlan.setOpUser(ServiceUtil.getOpUser());
            if (recordPlan.getOpUser() == null) {
                return ServiceUtil.getResponseFail("操作人员异常");
            }
            TResponse tResponse = service.addRecordPlan(recordPlan);

            if (Constants.CODE_SUC.equals(tResponse.getCode())) {
                JSONObject data = JSON.parseObject(tResponse.getJsonData());
                return Constants.getJsonResponse(Constants.CODE_SUC, data, null);
            } else {
                return Constants.getJsonResponse(Constants.CODE_FAIL, null, null);
            }
        } catch (Exception e) {
            logger.error("[doPlanSave]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    public String doPlanEdit(String dataString) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            TRecordPlan recordPlan = JSONObject.parseObject(dataString, TRecordPlan.class);
            recordPlan.setOpUser(ServiceUtil.getOpUser());
            if (recordPlan.getOpUser() == null) {
                return ServiceUtil.getResponseFail("操作人员异常");
            }
            if (recordPlan.getId() == 0) {
                return ServiceUtil.getResponseFail(PARAMETER_ERROR);
            }

            TResponse tResponse = service.editRecordPlan(recordPlan);
            if (Constants.CODE_SUC.equals(tResponse.getCode())) {
                JSONObject data = JSON.parseObject(tResponse.getJsonData());
                return Constants.getJsonResponse(Constants.CODE_SUC, data, "操作成功");
            } else {
                JSONObject data = JSON.parseObject(tResponse.getJsonData());
                int retValue = data.getIntValue("retValue");
                String retMsg = null;
                switch (retValue) {
                    case -1:
                        retMsg = DETAIL_ERROR_NO_ENTITY;
                        break;
                    case -2:
                        retMsg = "请先停止计划!";
                        break;
                    default:
                        retMsg = "未处理异常"+retValue;
                        break;
                }
                return Constants.getJsonResponse(Constants.CODE_FAIL, null, retMsg);
            }
        } catch (Exception e) {
            logger.error("[doPlanEdit]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    public String doPlanDel(String entityId) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            String user = ServiceUtil.getOpUser();
            if (user == null) {
                return ServiceUtil.getResponseFail("操作人员异常");
            }
            boolean resultFlag = service.deleteRecordPlan(Long.valueOf(entityId), ServiceUtil.getOpUser());
            if (resultFlag) {
                return Constants.getJsonResponse(Constants.CODE_SUC, null, "删除成功");
            } else {
                return ServiceUtil.getResponseFail("删除失败");
            }
        } catch (Exception e) {
            logger.error("[doPlanSave]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    @SkipInterfaceLog
    public String getRecordPlan(String entityId) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            TRecordPlan tRecordPlan = service.getRecordPlanById(Long.valueOf(entityId));
            if (tRecordPlan != null && tRecordPlan.getId() > 0) {
                return Constants.getResponse(Constants.CODE_SUC, tRecordPlan, "操作成功").toJsonString();
            } else {
                return Constants.getJsonResponse(Constants.CODE_ERROR, null, PARAMETER_ERROR);
            }
        } catch (Exception e) {
            logger.error("[getRecordPlan]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    @SkipInterfaceLog
    public String getRecordChannelList(String paramsObj, Integer pageNo, Integer pageSize, String dataMode) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            if (pageNo == null) {
                pageNo = 1;
            }
            if (pageSize == null) {
                pageSize = 20;
            }
            Map<String, String> params = new HashMap<>();
            if (paramsObj != null) {
                JSONObject jsonObject = JSONObject.parseObject(paramsObj);
                for (Map.Entry<String, Object> temp : jsonObject.entrySet()) {
                    params.put(temp.getKey(), temp.getValue() + "");
                }
            }
            TFilter tFilter = new TFilter();
            tFilter.setFilters(params);
            TPage page = new TPage(-1, pageNo, pageSize, "id", "desc", true);
            if ("simple".equals(dataMode)) {
                TRecordChannelSimplePage dataPage = service.findTRecordChannelSimplePage(page, tFilter);
                if (dataPage != null) {
                    return Constants.getResponse(Constants.CODE_SUC, dataPage, "操作成功").toJsonString();
                } else {
                    return Constants.getJsonResponse(Constants.CODE_ERROR, null, PARAMETER_ERROR);
                }
            } else {
                TRecordChannelPage dataPage = service.findTRecordChannelPage(page, tFilter);
                if (dataPage != null) {
                    return Constants.getResponse(Constants.CODE_SUC, dataPage, "操作成功").toJsonString();
                } else {
                    return Constants.getJsonResponse(Constants.CODE_ERROR, null, PARAMETER_ERROR);
                }
            }
        } catch (Exception e) {
            logger.error("[getRecordColList]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    @SkipInterfaceLog
    public String getRecordColList(String paramsObj, Integer pageNo, Integer pageSize, String dataMode) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            if (pageNo == null) {
                pageNo = 1;
            }
            if (pageSize == null) {
                pageSize = 20;
            }
            Map<String, String> params = new HashMap<>();
            if (paramsObj != null) {
                JSONObject jsonObject = JSONObject.parseObject(paramsObj);
                for (Map.Entry<String, Object> temp : jsonObject.entrySet()) {
                    params.put(temp.getKey(), temp.getValue() + "");
                }
            }
            TFilter tFilter = new TFilter();
            tFilter.setFilters(params);
            TPage page = new TPage(-1, pageNo, pageSize, "id", "desc", true);
            if ("simple".equals(dataMode)) {
                TRecordColSimplePage dataPage = service.findTRecordColSimplePage(page, tFilter);
                if (dataPage != null) {
                    return Constants.getResponse(Constants.CODE_SUC, dataPage, "操作成功").toJsonString();
                } else {
                    return Constants.getJsonResponse(Constants.CODE_ERROR, null, PARAMETER_ERROR);
                }
            } else {
                return Constants.getJsonResponse(Constants.CODE_ERROR, null, "wait to do");
            }
        } catch (Exception e) {
            logger.error("[getRecordColList]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    public String doChannelSave(String dataString) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            TRecordChannel recordChannel = JSONObject.parseObject(dataString, TRecordChannel.class);
            recordChannel.setOpUser(ServiceUtil.getOpUser());
            if (recordChannel.getOpUser() == null) {
                return ServiceUtil.getResponseFail("操作人员异常");
            }
            TResponse tResponse = service.addRecordChannel(recordChannel);

            if (Constants.CODE_SUC.equals(tResponse.getCode())) {
                JSONObject data = JSON.parseObject(tResponse.getJsonData());
                return Constants.getJsonResponse(Constants.CODE_SUC, data, null);
            } else {
                return Constants.getJsonResponse(Constants.CODE_FAIL, null, null);
            }
        } catch (Exception e) {
            logger.error("[doChannelSave]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    public String doChannelEdit(String dataString) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            TRecordChannel recordChannel = JSONObject.parseObject(dataString, TRecordChannel.class);
            recordChannel.setOpUser(ServiceUtil.getOpUser());
            if (recordChannel.getOpUser() == null) {
                return ServiceUtil.getResponseFail("操作人员异常");
            }
            TResponse tResponse = service.editRecordChannel(recordChannel);
            if (Constants.CODE_SUC.equals(tResponse.getCode())) {
                JSONObject data = JSON.parseObject(tResponse.getJsonData());
                return Constants.getJsonResponse(Constants.CODE_SUC, data, "操作成功");
            } else {
                return Constants.getJsonResponse(Constants.CODE_FAIL, null, null);
            }
        } catch (Exception e) {
            logger.error("[doChannelEdit]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    public String doChannelDel(String entityId) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            String user = ServiceUtil.getOpUser();
            if (user == null) {
                return ServiceUtil.getResponseFail("操作人员异常");
            }
            boolean resultFlag = service.deleteRecordChannel(Long.valueOf(entityId), user);
            if (resultFlag) {
                return Constants.getJsonResponse(Constants.CODE_SUC, null, "删除成功");
            } else {
                return ServiceUtil.getResponseFail("删除失败");
            }
        } catch (Exception e) {
            logger.error("[doChannelDel]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    // plan task start
    @SkipInterfaceLog
    public String getTaskLibraryList(String paramsObj, Integer pageNo, Integer pageSize ) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            if (pageNo == null) {
                pageNo = 1;
            }
            if (pageSize == null) {
                pageSize = 20;
            }
            Map<String, String> params = new HashMap<>();
            if (paramsObj != null) {
                JSONObject jsonObject = JSONObject.parseObject(paramsObj);
                for (Map.Entry<String, Object> temp : jsonObject.entrySet()) {
                    params.put(temp.getKey(), temp.getValue() + "");
                }
            }
            TFilter tFilter = new TFilter();
            tFilter.setFilters(params);
            TPage page = new TPage(-1, pageNo, pageSize, "task_start_time", "asc", true);
            TRecordTaskLibraryPage dataPage = service.findTRecordTaskLibraryPage(page, tFilter);
            if (dataPage != null) {
                return Constants.getResponse(Constants.CODE_SUC, dataPage, "操作成功").toJsonString();
            } else {
                return Constants.getJsonResponse(Constants.CODE_ERROR, null, PARAMETER_ERROR);
            }
        } catch (Exception e) {
            logger.error("[getTaskLibraryList]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    public String doTaskEdit(String dataString) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            TRecordTaskData recordTaskData = JSONObject.parseObject(dataString, TRecordTaskData.class);
            TResponse tResponse = service.editRecordTask(recordTaskData);
            if (Constants.CODE_SUC.equals(tResponse.getCode())) {
                JSONObject data = JSON.parseObject(tResponse.getJsonData());
                return Constants.getJsonResponse(Constants.CODE_SUC, data, "操作成功");
            } else {
                return Constants.getJsonResponse(Constants.CODE_FAIL, null, null);
            }
        } catch (Exception e) {
            logger.error("[doTaskEdit]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }


    @SkipInterfaceLog
    public String getSignalLibraryList(String paramsObj, Integer pageNo, Integer pageSize) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            if (pageNo == null) {
                pageNo = 1;
            }
            if (pageSize == null) {
                pageSize = 20;
            }
            Map<String, String> params = new HashMap<>();
            if (paramsObj != null) {
                JSONObject jsonObject = JSONObject.parseObject(paramsObj);
                for (Map.Entry<String, Object> temp : jsonObject.entrySet()) {
                    params.put(temp.getKey(), temp.getValue() + "");
                }
            }
            TFilter tFilter = new TFilter();
            tFilter.setFilters(params);
            TPage page = new TPage(-1, pageNo, pageSize, "create_time", "desc", true);
            TRecordSignalPage dataPage = service.findTRecordSignalPage(page, tFilter);
            if (dataPage != null) {
                return Constants.getResponse(Constants.CODE_SUC, dataPage, "操作成功").toJsonString();
            } else {
                return Constants.getJsonResponse(Constants.CODE_ERROR, null, PARAMETER_ERROR);
            }
        } catch (Exception e) {
            logger.error("[getSignalLibraryList]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    public String doSignalSave(String dataString) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            TRecordSignal tRecordSignal = JSON.parseObject(dataString, TRecordSignal.class);
            tRecordSignal.setOpUser(ServiceUtil.getOpUser());
            if (tRecordSignal.getOpUser() == null) {
                return ServiceUtil.getResponseFail("操作人员异常");
            }
            TResponse tResponse = service.addRecordSignal(tRecordSignal);

            if (Constants.CODE_SUC.equals(tResponse.getCode())) {
                JSONObject data = JSON.parseObject(tResponse.getJsonData());
                return Constants.getJsonResponse(Constants.CODE_SUC, data, "创建成功");
            } else if (Constants.CODE_ERROR_SIGNALNAME_EXIST.equals(tResponse.getCode())) {
                return Constants.getJsonResponse(Constants.CODE_ERROR_SIGNALNAME_EXIST, null, "创建失败");
            } else {
                return Constants.getJsonResponse(Constants.CODE_FAIL, null, "创建失败");
            }
        } catch (Exception e) {
            logger.error("[doSignalSave]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    public String doSignalDel(String entityId) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            String user = ServiceUtil.getOpUser();
            if (user == null) {
                return ServiceUtil.getResponseFail("操作人员异常");
            }
            TResponse tResponse = service.deleteRecordSignal(Long.valueOf(entityId), ServiceUtil.getOpUser());
            String msg = tResponse.getMsg();
            if (tResponse.getCode().equals(Constants.CODE_SUC)) {
                return Constants.getJsonResponse(Constants.CODE_SUC, null, msg);
            } else if (Constants.CODE_ERROR_SIGNAL_RELATED.equals(tResponse.getCode())) {
                return Constants.getJsonResponse(Constants.CODE_ERROR_SIGNAL_RELATED, null, msg);
            } else {
                return Constants.getJsonResponse(Constants.CODE_FAIL, null, msg);
            }
        } catch (Exception e) {
            logger.error("[doSignalDel]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    @SkipInterfaceLog
    public String getRecordSignal(String entityId) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            TRecordSignal tRecordSignal = service.getRecordSignalById( Long.valueOf(entityId));
            if (tRecordSignal != null && tRecordSignal.getId() > 0) {
                return Constants.getResponse(Constants.CODE_SUC, tRecordSignal, "操作成功").toJsonString();
            } else {
                return Constants.getJsonResponse(Constants.CODE_ERROR, null, PARAMETER_ERROR);
            }
        } catch (Exception e) {
            logger.error("[getRecordSignal]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }


    public String doSignalEdit(String dataString) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            TRecordSignal tRecordSignal = JSONObject.parseObject(dataString, TRecordSignal.class);
            tRecordSignal.setOpUser(ServiceUtil.getOpUser());
            if (tRecordSignal.getOpUser() == null) {
                return ServiceUtil.getResponseFail("操作人员异常");
            }
            TResponse tResponse = service.editRecordSignal(tRecordSignal);
            if (Constants.CODE_SUC.equals(tResponse.getCode())) {
                JSONObject data = JSON.parseObject(tResponse.getJsonData());
                return Constants.getJsonResponse(Constants.CODE_SUC, data, "修改成功");
            } else {
                return Constants.getJsonResponse(Constants.CODE_FAIL, null, "修改失败");
            }
        } catch (Exception e) {
            logger.error("[doSignalEdit]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }


    @SkipInterfaceLog
    public String getChannelSignalLibraryList(String paramsObj, Integer pageNo, Integer pageSize) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            if (pageNo == null) {
                pageNo = 1;
            }
            if (pageSize == null) {
                pageSize = 20;
            }
            Map<String, String> params = new HashMap<>();
            if (paramsObj != null) {
                JSONObject jsonObject = JSONObject.parseObject(paramsObj);
                for (Map.Entry<String, Object> temp : jsonObject.entrySet()) {
                    params.put(temp.getKey(), temp.getValue() + "");
                }
            }
            TFilter tFilter = new TFilter();
            tFilter.setFilters(params);
            TPage page = new TPage(-1, pageNo, pageSize, "create_time", "desc", true);
            TRecordChannelSignalPage dataPage = service.findTRecordChannelSignalPage(page, tFilter);
            if (dataPage != null) {
                return Constants.getResponse(Constants.CODE_SUC, dataPage, "操作成功").toJsonString();
            } else {
                return Constants.getJsonResponse(Constants.CODE_ERROR, null, PARAMETER_ERROR);
            }
        } catch (Exception e) {
            logger.error("[getChannelSignalLibraryList]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    public String doChannelSignalSave(String dataString) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            TRecordChannelSignal tRecordChannelSignal = JSON.parseObject(dataString, TRecordChannelSignal.class);
            tRecordChannelSignal.setOpUser(ServiceUtil.getOpUser());
            if (tRecordChannelSignal.getOpUser() == null) {
                return ServiceUtil.getResponseFail("操作人员异常");
            }
            TResponse tResponse = service.addRecordChannelSignal(tRecordChannelSignal);

            if (Constants.CODE_SUC.equals(tResponse.getCode())) {
                JSONObject data = JSON.parseObject(tResponse.getJsonData());
                return Constants.getJsonResponse(Constants.CODE_SUC, data, "创建成功");
            } else if (Constants.CODE_ERROR_SIGNALNAME_EXIST.equals(tResponse.getCode())) {
                return Constants.getJsonResponse(Constants.CODE_ERROR_SIGNALNAME_EXIST, null, "创建失败");
            } else {
                return Constants.getJsonResponse(Constants.CODE_FAIL, null, "创建失败");
            }
        } catch (Exception e) {
            logger.error("[doChannelSignalSave]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    public String doChannelSignalDel(String entityId) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            String user = ServiceUtil.getOpUser();
            if (user == null) {
                return ServiceUtil.getResponseFail("操作人员异常");
            }
            boolean resultFlag = service.deleteRecordChannelSignal(Long.valueOf(entityId), ServiceUtil.getOpUser());
            if (resultFlag) {
                return Constants.getJsonResponse(Constants.CODE_SUC, null, "删除成功");
            } else {
                return ServiceUtil.getResponseFail("删除失败");
            }
        } catch (Exception e) {
            logger.error("[doChannelSignalDel]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    @SkipInterfaceLog
    public String getRecordChannelSignal(String entityId) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            TRecordChannelSignal tRecordChannelSignal = service.getRecordChannelSignalById( Long.valueOf(entityId));
            if (tRecordChannelSignal != null && tRecordChannelSignal.getId() > 0) {
                return Constants.getResponse(Constants.CODE_SUC, tRecordChannelSignal, "操作成功").toJsonString();
            } else {
                return Constants.getJsonResponse(Constants.CODE_ERROR, null, PARAMETER_ERROR);
            }
        } catch (Exception e) {
            logger.error("[getRecordSignal]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }


    public String doChannelSignalEdit(String dataString) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            TRecordChannelSignal tRecordSignal = JSONObject.parseObject(dataString, TRecordChannelSignal.class);
            tRecordSignal.setOpUser(ServiceUtil.getOpUser());
            if (tRecordSignal.getOpUser() == null) {
                return ServiceUtil.getResponseFail("操作人员异常");
            }
            TResponse tResponse = service.editRecordChannelSignal(tRecordSignal);
            if (Constants.CODE_SUC.equals(tResponse.getCode())) {
                JSONObject data = JSON.parseObject(tResponse.getJsonData());
                return Constants.getJsonResponse(Constants.CODE_SUC, data, "修改成功");
            } else {
                return Constants.getJsonResponse(Constants.CODE_FAIL, null, "修改失败");
            }
        } catch (Exception e) {
            logger.error("[doSignalEdit]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    public String doChannelSignalStart(String entityId) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            String user = ServiceUtil.getOpUser();
            if (user == null) {
                return ServiceUtil.getResponseFail("操作人员异常");
            }
            TResponse tResponse = service.startRecordChannelSignal(Long.valueOf(entityId), user);
            JSONObject data = JSON.parseObject(tResponse.getJsonData());
            if (Constants.CODE_SUC.equals(tResponse.getCode())) {
                return Constants.getJsonResponse(Constants.CODE_SUC, data, "启动成功 " + tResponse.getJsonData());
            } else {
                return Constants.getJsonResponse(Constants.CODE_FAIL, data, "启动失败" + tResponse.getJsonData());
            }

        } catch (Exception e) {
            logger.error("[doChannelSignalStart]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }

    public String doChannelSignalStop(String entityId) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            String user = ServiceUtil.getOpUser();
            if (user == null) {
                return ServiceUtil.getResponseFail("操作人员异常");
            }
            TResponse tResponse = service.stopRecordChannelSignal(Long.valueOf(entityId), user);
            JSONObject data = JSON.parseObject(tResponse.getJsonData());
            if (Constants.CODE_SUC.equals(tResponse.getCode())) {
                return Constants.getJsonResponse(Constants.CODE_SUC, data, "关闭成功 " + tResponse.getJsonData());
            } else {
                return Constants.getJsonResponse(Constants.CODE_FAIL, data, "关闭失败 " + tResponse.getJsonData());
            }

        } catch (Exception e) {
            logger.error("[doChannelSignalStop]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }


    @SkipInterfaceLog
    public String getRecordChannelSignalTableList(String paramsObj, Integer pageNo, Integer pageSize) {
        try {
            RecordWebService.Iface service = getRecordWebService();
            if (pageNo == null) {
                pageNo = 1;
            }
            if (pageSize == null) {
                pageSize = 20;
            }
            Map<String, String> params = new HashMap<>();
            if (paramsObj != null) {
                JSONObject jsonObject = JSONObject.parseObject(paramsObj);
                for (Map.Entry<String, Object> temp : jsonObject.entrySet()) {
                    params.put(temp.getKey(), temp.getValue() + "");
                }
            }
            TFilter tFilter = new TFilter();
            tFilter.setFilters(params);
            TPage page = new TPage(-1, pageNo, pageSize, "create_time", "desc", true);
            TRecordChannelSignalTablePage dataPage = service.findTRecordChannelSignalTablePage(page, tFilter);
            if (dataPage != null) {
                return Constants.getResponse(Constants.CODE_SUC, dataPage, "操作成功").toJsonString();
            } else {
                return Constants.getJsonResponse(Constants.CODE_ERROR, null, PARAMETER_ERROR);
            }
        } catch (Exception e) {
            logger.error("[getRecordChannelSignalTableList]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }

    }

    @SkipAuthCheck
    @SkipInterfaceLog
    public String updateRecordVideoStatus(Long signalId, Long taskId, Long videoId, Integer videoStatus) {
        try {
            if (signalId == null || taskId == null || videoId == null || videoStatus == null) {
                return Constants.getJsonResponse(Constants.CODE_ERROR_PARAM, null, "参数有误");
            }


            RecordWebService.Iface service = getRecordWebService();
            TResponse tResponse = service.updateRecordVideoStatus(signalId, taskId, videoId, videoStatus);
            String msg = tResponse.getMsg();
            if (Constants.CODE_SUC.equals(tResponse.getCode())) {
                return Constants.getJsonResponse(Constants.CODE_SUC, null, "success | " + msg);
            } else {
                return Constants.getJsonResponse(Constants.CODE_FAIL, null, "fail | " + msg);
            }
        } catch (Exception e) {
            logger.error("[updateRecordVideoStatus]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }


    @SkipAuthCheck
    @SkipInterfaceLog
    public String updateRecordTaskStatus(Long taskId, Integer taskStatus) {
        try {
            if (taskId == null|| taskStatus == null) {
                return Constants.getJsonResponse(Constants.CODE_ERROR_PARAM, null, "参数有误");
            }

            RecordWebService.Iface service = getRecordWebService();
            TResponse tResponse = service.updateRecordTaskStatus(taskId, taskStatus);
            String msg = tResponse.getMsg();
            if (Constants.CODE_SUC.equals(tResponse.getCode())) {
                return Constants.getJsonResponse(Constants.CODE_SUC, null, "success | " + msg);
            } else {
                return Constants.getJsonResponse(Constants.CODE_FAIL, null, "fail | " + msg);
            }
        } catch (Exception e) {
            logger.error("[updateRecordTaskStatus]", e);
            return getResponseWithJsonp(Constants.CODE_ERROR, null, INTERFACE_ERROR);
        }
    }




}
